/* $Id: UserDelegateImpl.java 
 * Copyright (C) 2011, TRAKHEES
 *  
 * Revision History
 *
 * Date  			Author 		    	Remarks
 * ---------------------------------------------------------------------------------
 *
 */
package ae.pcfc.etks.online.common.delegate.provider;

import java.io.Serializable;
import java.util.List;

import ae.pcfc.etks.online.common.delegate.UserDelegate;
import ae.pcfc.etks.online.common.exception.AdminWorkflowException;
import ae.pcfc.etks.online.common.facade.UserFacade;
import ae.pcfc.etks.online.common.manager.MailManager;
import ae.pcfc.etks.online.common.vo.ActivityVO;
import ae.pcfc.etks.online.common.vo.ClientEmailVO;
import ae.pcfc.etks.online.common.vo.PagingVO;
import ae.pcfc.etks.online.common.vo.PasswordResetVO;
import ae.pcfc.etks.online.common.vo.SearchCriteriaActivityVO;
import ae.pcfc.etks.online.common.vo.SearchCriteriaCompanyVO;
import ae.pcfc.etks.online.common.vo.SearchCriteriaPersonVO;
import ae.pcfc.etks.online.common.vo.UserDetailVO;
import ae.pcfc.etks.online.common.vo.UserVO;
import ae.pcfc.etks.online.common.vo.WorkflowRequestVO;

public class UserDelegateImpl extends BaseDelegateImpl implements UserDelegate {
    	/*
	 * Here we coordinate between the Facade service which handles DB entities
	 * and the WF both will be looked up with service locator normally we will
	 * have 1-1 relationship between the delegate and the facade and 1-1
	 * relationship between the delegate and the WF service which means for
	 * CompanyRegistrationDelegate there will be ClientRegistrationFacade &
	 * CompanyRegistrationWF validations that related to DB vs WF are maintained
	 * here ie user cannot issue a new request while he already have a request
	 * in the wf Exception are translated in to business exception
	 */
	private static final long serialVersionUID = -5774728325149677517L;

	/**
	 * findUserByUserName
	 * 
	 * @see ae.pcfc.etks.online.common.delegate.UserDelegate#findUserByUserName(java.lang.String)
	 * 
	 */
	public UserVO findUserByUserName(String strUserName) {
		return serviceLocator.getFacadeService(UserFacade.class).findUserByUserName(strUserName);
	}

	/**
	 * getUserList
	 * 
	 * @see ae.pcfc.etks.online.common.delegate.UserDelegate#getUserList()
	 * 
	 */
	public List<UserVO> getUserList() {

		return serviceLocator.getFacadeService(UserFacade.class).getUserList();
	}

	/**
	 * getUserListByPagingParameters
	 * 
	 * @see ae.pcfc.etks.online.common.delegate.UserDelegate#getUserListByPagingParameters(ae.pcfc.etks.online.common.vo.PagingVO)
	 * 
	 */
	public List<UserVO> getUserListByPagingParameters(PagingVO pagingVO) {

		return serviceLocator.getFacadeService(UserFacade.class).getUserListByPagingParameters(pagingVO);
	}

	/**
	 * findUserByPrimaryKey
	 * 
	 * @see ae.pcfc.etks.online.common.delegate.UserDelegate#findUserByPrimaryKey(java.lang.Long)
	 * 
	 */
	public UserVO findUserByPrimaryKey(Long id) {
		return serviceLocator.getFacadeService(UserFacade.class).findUserByPrimaryKey(id);
	}

	/**
	 * findUserByEmail
	 * 
	 * @see ae.pcfc.etks.online.common.delegate.UserDelegate#findUserByEmail(java.lang.String)
	 * 
	 */
	public UserVO findUserByEmail(String email) {
		return serviceLocator.getFacadeService(UserFacade.class).findUserByEmail(email);
	}

	/**
	 * getUserNameAndPassword
	 * 
	 * @see ae.pcfc.etks.online.common.delegate.UserDelegate#getUserNameAndPassword(ae.pcfc.etks.online.common.vo.ClientEmailVO)
	 * 
	 */
	public void getUserNameAndPassword(ClientEmailVO clientEmail) {
		
		this.getServiceLocator().getManager(MailManager.class).sendMail(clientEmail.getStrEmailAddress(), clientEmail.getStrEmailSubject(), clientEmail.getStrEmailBody(), null);
		
	}

	/**
	 * resetPassword
	 * 
	 * @see ae.pcfc.etks.online.common.delegate.UserDelegate#resetPassword(ae.pcfc.etks.online.common.vo.PasswordResetVO)
	 * 
	 */
	public void resetPassword(PasswordResetVO passwordResetVO) {
		
		this.serviceLocator.getFacadeService(UserFacade.class).resetPassword(passwordResetVO);
		
	}

	/**
	 * lockUser
	 * 
	 * @see ae.pcfc.etks.online.common.delegate.UserDelegate#lockUser(ae.pcfc.etks.online.common.vo.UserVO)
	 * 
	 */
	public void lockUser(UserVO userVO) {
		
		this.serviceLocator.getFacadeService(UserFacade.class).lockUser(userVO);
		
	}

	/**
	 * addUser
	 * 
	 * @see ae.pcfc.etks.online.common.delegate.UserDelegate#addUser(ae.pcfc.etks.online.common.vo.UserVO)
	 * 
	 */
	public void addUser(UserVO userVO) {
		this.serviceLocator.getFacadeService(UserFacade.class).addUser(userVO);
		
	}
	/**
	 * findUserDetailByUserName
	 * 
	 * @see ae.pcfc.etks.online.common.delegate.UserDelegate#findUserDetailByUserName(java.lang.String)
	 * 
	 */
	public UserDetailVO findUserDetailByUserName(String strUserName){
		return this.serviceLocator.getFacadeService(UserFacade.class).findUserDetailByUserName(strUserName);
	}

	/**
	 * searchUsersByTrakheesId
	 * 
	 * @see ae.pcfc.etks.online.common.delegate.UserDelegate#searchUsersByTrakheesId(java.lang.String)
	 * 
	 */
	public List<UserDetailVO> searchUsersByTrakheesId(String strTrakheesId){
		return this.serviceLocator.getFacadeService(UserFacade.class).searchUsersByTrakheesId(strTrakheesId);
	}
	
	/**
	 * searchUsersByClientPerson
	 * 
	 * @see ae.pcfc.etks.online.common.delegate.UserDelegate#searchUsersByClientPerson(ae.pcfc.etks.online.common.vo.SearchCriteriaPersonVO)
	 * 
	 */
	public List<UserDetailVO> searchUsersByClientPerson(SearchCriteriaPersonVO searchCriteriaPersonVO){
		return this.serviceLocator.getFacadeService(UserFacade.class).searchUsersByClientPerson(searchCriteriaPersonVO);
	}
	
	/**
	 * searchUsersByClientCompany
	 * 
	 * @see ae.pcfc.etks.online.common.delegate.UserDelegate#searchUsersByClientCompany(ae.pcfc.etks.online.common.vo.SearchCriteriaCompanyVO)
	 * 
	 */
	public List<UserDetailVO> searchUsersByClientCompany(SearchCriteriaCompanyVO searchCriteriaCompanyVO){
		return this.serviceLocator.getFacadeService(UserFacade.class).searchUsersByClientCompany(searchCriteriaCompanyVO);
	}

	/**
	 * findActivitiesOfClientCompany
	 * 
	 * @see ae.pcfc.etks.online.common.delegate.UserDelegate#findActivitiesOfClientCompany(ae.pcfc.etks.online.common.vo.SearchCriteriaActivityVO)
	 * 
	 */
	public List<ActivityVO> findActivitiesOfClientCompany(SearchCriteriaActivityVO searchCriteriaActivityVO) {
		return this.serviceLocator.getFacadeService(UserFacade.class).findActivitiesOfClientCompany(searchCriteriaActivityVO);
	}

	/**
	 * getUserWorkflowRequests
	 * 
	 * @see ae.pcfc.etks.online.common.delegate.UserDelegate#getUserWorkflowRequests(java.lang.String)
	 * 
	 */
	public List<WorkflowRequestVO> getUserWorkflowRequests(String userName) {
	    return this.serviceLocator.getFacadeService(UserFacade.class).getUserWorkflowRequests(userName);
	}
	
	/*
	 * public ClientCompanyVO userValidation(String userName, String password) {
	 * return
	 * serviceLocator.getFacadeService(UserFacade.class).userValidation(userName
	 * , password); }
	 */

	public List<String> getTaskInformation(Integer incedentNo, String processCode)
	{
	    try{
	    	
	    	
			UserFacade userFacade = serviceLocator.getFacadeService(UserFacade.class);
			
			return userFacade.getIncidentNoStepNames(incedentNo, processCode);
			
			
	    }catch(Throwable t){	    	
	    	throw new AdminWorkflowException(t);
	    }
	}
}
